package com.sean.first

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object WordCount {
  def main(args: Array[String]): Unit = {
    System.setProperty("hadoop.home.dir", "D:\\hadoop-common-2.2.0-bin-master")
    //创建SparkConf的对象
    val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")
    val sc = new SparkContext(config)
    val lines: RDD[String] = sc.textFile("input")
    val words: RDD[String] = lines.flatMap(_.split(" "))
    val wordTOone: RDD[(String, Int)] = words.map((_, 1))
    val wordToSum: RDD[(String, Int)] = wordTOone.reduceByKey(_ + _)
    val result: Array[(String, Int)] = wordToSum.collect();
    result.foreach(println)

  }
}
